import json
import requests
from test_case import conftest
import time

class get_lessee_info:

    def query_allLessee(self):
        try:
            t = time.time()
            random_time = str(int(t))
            url = conftest.base_url + '/api-zendai/investment/e/lessee/queryAllLesseeList'
            data = {
                'pageNum': 1,
                'pageSize': 9999,
                'mallCode': 'XMBN',
                'randomTime': random_time
            }
            result = requests.get(url, headers=conftest.fin_header, params=data)
            print(result.text)
            new_result = json.loads(result.text)
            if len(new_result['data']['records']) != 0 :
                for a in range(len(new_result['data']['records'])):
                    if new_result['data']['records'][a]['brandNames'] == None:
                        continue
                    else:
                        return new_result['data']['records'][a]
        except BaseException:
            return False

    def query_lessee_brandinfo(self, lesseeId):
        try:
            new_lesseeId = lesseeId
            t = time.time()
            random_time = str(int(t))
            url = conftest.base_url + '/api-zendai/investment/e/lessee/lesseeDetail'
            data = {
                'lesseeId': new_lesseeId,
                'randomTime': random_time
            }
            result = requests.get(url, headers=conftest.fin_header, params=data)
            new_result = json.loads(result.text)
            if len(new_result['data']['lesseeBrandVoList']) != None:
                return new_result['data']['lesseeBrandVoList'][0]
            else:
                return False
        except BaseException:
            return False



# a = get_lessee_info()
# resultData = a.query_lessee_brandinfo(14112)
# print(resultData)